import random
from zidong.util.SougouPushAutomation import SougouPushAutomation
from DrissionPage import ChromiumPage,ChromiumOptions
import pandas as pd

USER_AGENTS = [
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
    'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0',
    'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36',
    'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36',
    'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36',
    'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
]
headers = {
    #随机选择一个用户代理
    random.choice(USER_AGENTS)
}

co = ChromiumOptions()
# 设置header
co.set_user_agent(headers)
# 阻止“自动保存密码”的提示气泡
co.set_pref('credentials_enable_service', False)
# 阻止“要恢复页面吗？Chrome未正确关闭”的提示气泡
co.set_argument('--hide-crash-restore-bubble')
# 禁用沙盒
# co.set_argument('--no-sandbox')
# 无痕
co.incognito(True)
# 无头
# co.headless(True)
# 创建页面对象，并启动或接管浏览器
page = ChromiumPage(co)
mcsAmt = SougouPushAutomation(page)
# 出现的弹窗都是确认
page.set.auto_handle_alert(all_tabs=True)

def main():
    __name__ = "__main__"
    url  ='https://zhanzhang.sogou.com/index.php/site/index'
    username = 'cuihongjiang2000@163.com'
    password = 'cuihj662004'
    links_file = r"E:\project\py-pro\automation\cms-links.txt"
    domain_name = 'www.jiangshuntech.com'
    
    article_release(url,username,password,domain_name,links_file)
    # page.quit()

def article_release(url,username,password,domain_name,links_file):
    mcsAmt.start(url,username,password)
    mcsAmt.article_manage()
    seo_data=[]
    with open(links_file, 'r') as file:
        for line in file:
            seo_data.append(line)
            if len(seo_data) ==19:
                mcsAmt.article_copy(domain_name,seo_data)
                seo_data=[]

if __name__ == "__main__":
    main()